package collection.Demo09;

import java.util.HashSet;
import java.util.Iterator;

/**
 * @Author Miku
 * @Create 2021/4/16 15:30
 * HashSet集合的使用
 */
public class Test2 {
    public static void main(String[] args) {
        //新建集合
        HashSet<String> hashSet = new HashSet<>();
        //1.添加元素
        hashSet.add("miku");
        hashSet.add("sakura");
        hashSet.add("luka");
        hashSet.add("test");
        System.out.println("元素个数:"+hashSet.size());
        System.out.println(hashSet);

        //遍历
        for (String s : hashSet) {
            System.out.println(s);
        }

        Iterator<String> iterator = hashSet.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }

    }
}
